// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'es6-promise/auto'
import Vue from 'vue'
import store from './store/store'
import App from './App'
import ElementUI from 'element-ui'
import Echarts from 'echarts'
import 'element-ui/lib/theme-chalk/index.css'
import '@/styles/common.css' //全局css
import '@/styles/resui.css' //全局css
// import NProgress from 'nprogress'; //路由进度条
// import 'nprogress/nprogress.css'; //路由进度条样式
import axios from './utils/axios.js'; //引入axios
import fontFormatter from './utils/util.js'
import validater from './utils/rules.js'
import * as filters from './filters' //引入全局过滤器
import router from './router' //最后导入路由防止页面css被覆盖
import elementResizeDetectorMaker from "element-resize-detector"; //引入页面大小改动钩子
import promptBox from '@/components/promptBox.js'
import tips from '@/components/tips.js'
import Print from 'vue-print-nb' //打印插件
Vue.use(Print)

Vue.prototype.$promptBox = promptBox;
Vue.prototype.$tips = tips;

//添加到全局过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
});

Vue.use(ElementUI);
Vue.prototype.$ELEMENT = { size: 'mini' };

Vue.config.productionTip = false;

Vue.prototype.$rules = validater;
Vue.prototype.$font = fontFormatter
Vue.prototype.$erd = elementResizeDetectorMaker();
Vue.prototype.$axios = axios
window.axios = axios
window.router = router;
window.Loading = ElementUI.Loading;

Storage.prototype.setExpire = (key, value, expire) => {
  let obj = {
    data: value,
    time: Date.now(),
    expire: expire
  };
  //localStorage 设置的值不能为对象,转为json字符串
  localStorage.setItem(key, JSON.stringify(obj));
}

Storage.prototype.getExpire = key => {
  let val = localStorage.getItem(key);
  if (!val) {
    return val;
  }
  val = JSON.parse(val);
  if (Date.now() - val.time > val.expire) {
    localStorage.removeItem(key);
    return null;
  }
  return val.data;
}

Vue.prototype.$echarts = Echarts

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  store,
  template: '<App/>'
})
